<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let obj = {
            name: '张学友',
            age: 20,
            dance: function () {
                console.log('我会跳舞');
            },
            msg: { num: 33 }
        }
        let newObj = {};
        function deepcopy(obj, newObj) {
            for (const key in obj) {
                const item = obj[key]
                if (item instanceof Function) {
                    newObj[key] = item
                } else if (item instanceof Array) {
                    newObj[key] = []
                    deepcopy(item, newObj[key])
                } else if (item instanceof Object) {
                    newObj[key] = {}
                    deepcopy(item, newObj[key])
                } else {
                    newObj[key] = item
                }
            }
        }
        deepcopy(obj, newObj)
        // for (const key in obj) {
        //     newObj[key] = obj[key]
        // }

        console.log(newObj);
        newObj.dance()
    </script>
</body>

</html>